<template>
  <view
    class="content ba_img"
    :style="{
      //   'padding-top': height + 'px',
    }"
  >
    <view
      :style="{
        height: statusBarHeight + 'px',
      }"
    >
    </view>
    <view
      class="head"
      :style="{
        // background: isHeadBack ? 'rgba(39,39,39)' : 'rgba(0,0,0,0)',
        paddingTop: statusBarHeight + 'px',
      }"
    >
      <view class="head_left">
        <u-icon
          name="arrow-left"
          color="#eeeeee"
          size="24"
          :bold="true"
          @click="toBack"
        ></u-icon>
      </view>
      <view class="text">山海奥义</view>
    </view>

    <u-tabs
      class="tabs"
      :list="list1"
      @click="click"
      :activeStyle="{
        color: '#eee',
        fontWeight: 'bold',
        transform: 'scale(1.05)',
        'font-size': '32rpx',
      }"
      lineColor="#eee"
      :inactiveStyle="{
        color: '#ADADAD',
        transform: 'scale(1)',
        'font-size': '32rpx',
      }"
      :current="currentIndex"
      :style="{
        'margin-top': tabTop + 'px',
        // background: isHeadBack ? 'rgba(39,39,39)' : 'rgba(0,0,0,0)',
      }"
    ></u-tabs>
    <view class="input_box">
      <view class="inp">
        <u--input
          placeholder="搜索"
          border="none"
          placeholderStyle="font-size:30rpx;color:#ADADAD;"
          color="#ADADAD"
          v-model="search"
          @change="change"
          inputAlign="center"
          @confirm="confirm"
        ></u--input>
      </view>
    </view>
    <scroll-view
      class="scroll_box"
      :style="{
        height: height + 'px',
        'margin-top': '20rpx',
      }"
      :scroll-y="true"
      @scroll="scroll"
    >
      <view class="box1">
        <aoyiHall :isWhite="true" :list="list" v-if="showList"></aoyiHall>
      </view>
    </scroll-view>
	<floatingBall></floatingBall>
  </view>
</template>

<script>
import navigatorS from "@/components/navigatorS.vue"; //导航仪
import aoyiHall from "./components/aoyiHall.vue"; //奥义堂
import { Region, aoyiList } from "@/common/api/mountainSea.js";
export default {
  components: {
    navigatorS,
    aoyiHall,
  },
  data() {
    return {
      statusBarHeight: 0,
      height: 0,
      height1: 0,
      tabTop: 0,
      value: "",
      list1: [],
      list: [],
      currentIndex: 0,
      currentId: 1,
      search: "",
      isHeadBack: false,
      showList:false
    };
  },
  onLoad(options) {
    if (options && options.id) {
      this.currentId = options.id;
    }
    this.getRegion();
    this.getList();
  },
  created() {
    // this.getHeight()
    // const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度
    // this.statusBarHeight = statusBarHeight.statusBarHeight;
    // this.$nextTick(() => {
    //   uni
    //     .createSelectorQuery()
    //     .select(".head")
    //     .boundingClientRect((data) => {
    //       this.height = data.height;
    //     })
    //     .exec();
    // });
  },
  methods: {
    scroll(e) {
      if (e.target.scrollTop == 0) {
        this.isHeadBack = false;
      } else {
        this.isHeadBack = true;
      }
    },
    // 获取各种高度
    getHeight() {
      const statusBarHeight = uni.getSystemInfoSync(); // 获取手机状态栏高度
      this.statusBarHeight = statusBarHeight.statusBarHeight;
      console.log(this.statusBarHeight, "状态栏高度");
      this.windowHeihgt = statusBarHeight.windowHeight;
      console.log(this.windowHeihgt, "总高度");
      this.$nextTick(() => {
        const query = uni.createSelectorQuery().in(this);
        query.select(".head").fields({
          size: true,
        });
        query.select(".tabs").fields({
          size: true,
        });
        query.select(".input_box").fields({
          size: true,
        });
        query.exec((data) => {
          console.log(data, "各种高度");
          let sum = 0;
          data.forEach((item) => {
            sum += item.height;
          });
          this.height = this.windowHeihgt - sum - this.statusBarHeight;
          //   this.height1 = data[0].height;
          this.tabTop = data[0].height + this.statusBarHeight;
          console.log(data[0].height, "头部高度");
          console.log(this.height, "滚动取高度");
        });
      });
    },
    getList() {
      aoyiList({
        address: this.currentId,
        search: this.search,
      }).then((res) => {
        console.log("ressss", res);
        this.list = res.data.list.data;
        this.showList = true
      });
    },
    getRegion() {
      Region({}).then((res) => {
        console.log("resssss", res);
        this.getHeight();
        this.list1 = res.data.list.map((item, index) => {
          if (item.id == this.currentId) {
            this.currentIndex = index;
          }
          return {
            ...item,
            name: item.name + "-" + item.chan,
          };
        });
      });
    },
    toBack() {
      uni.navigateBack({
        delta: 1,
      });
    },
    change(e) {
      this.getList();
    },
    confirm(e) {
      console.log("eeeee", e);
      this.search = e;
      this.getList();
    },
    click(e) {
      this.showList = false
      console.log("1111", e);
      this.currentIndex = e.index;
      this.currentId = e.id;
      this.getList();
    },
  },
};
</script>

<style scoped lang="scss">
.ba_img {
  margin: 0;
  background: url("/static/images/index.png") no-repeat;
  background-size: 100% 100%;
  background-attachment: fixed;
  box-sizing: border-box;
  position: fixed;
}
.head {
  width: 100%;
  // padding: 18rpx 0 47rpx;
  position: fixed;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 99;

  .head_left {
    position: absolute;
    left: 30rpx;
  }

  .text {
    font-size: 36rpx;
    font-family: PingFang SC-Bold, PingFang SC;
    font-weight: 400;
    color: #eeeeee;
  }
}
.input_box {
  padding: 0 30rpx;
  box-sizing: border-box;
}
.inp {
  width: 100%;
  height: 80rpx;
  background: rgba(39, 44, 41, 0.5);
  border-radius: 40rpx;
  display: flex;
  align-items: center;
  margin-top: 32rpx;
}
.box1 {
  width: 100%;
  padding: 0 30rpx;
  box-sizing: border-box;
}
.empty_view {
  margin-top: 300rpx;
  image {
    margin: 0 auto;
    width: 410rpx;
    height: 410rpx;
  }
  view {
    font-size: 30rpx;
    color: #d8d8d8;
    text-align: center;
  }
}
</style>